from machine import Pin

led = Pin(2, Pin.OUT)

def get_html_index():
    return """<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>ESP32 CONTROL</title>
    <style>
        body {font-family: Arial; text-align: center; margin: 0 auto; padding: 20px;}
        .btn {
            background-color: #4CAF50;
            border: none;
            color: white;
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 10px 5px;
            cursor: pointer;
            border-radius: 8px;
            width: 150px;
        }
        .btn-off {background-color: #f44336;}
        .btn-gpio {background-color: #2196F3;}
        .status {font-size: 24px; margin: 20px;}
        .gpio-control {
            margin: 30px auto;
            padding: 20px;
            border-radius: 10px;
            max-width: 500px;
        }
        select {
            padding: 12px 20px;
            margin: 8px 0;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <h1>ESP32 CONTROLLER</h1>
    
    <div class="status">
        LED STATUS: <span id="led-status">""" + ("ON" if led.value() else "OFF") + """</span>
    </div>
    
    <div>
        <a href="/led/on"><button class="btn">LED ON</button></a>
        <a href="/led/off"><button class="btn btn-off">LED OFF</button></a>
    </div>
    
    <div class="gpio-control">
        <h2>SET GPIO</h2>
        <form action="/gpio/set" method="get">
            <select name="pin" required>
                <option value="" disabled selected>Select GPIO Pin</option>
                <option value="0">GPIO 0</option>
                <option value="2">GPIO 2</option>
                <option value="4">GPIO 4</option>
                <option value="5">GPIO 5</option>
                <option value="12">GPIO 12</option>
                <option value="13">GPIO 13</option>
                <option value="14">GPIO 14</option>
                <option value="15">GPIO 15</option>
                <option value="16">GPIO 16</option>
                <option value="17">GPIO 17</option>
                <option value="18">GPIO 18</option>
                <option value="19">GPIO 19</option>
                <option value="21">GPIO 21</option>
                <option value="22">GPIO 22</option>
                <option value="23">GPIO 23</option>
                <option value="25">GPIO 25</option>
                <option value="26">GPIO 26</option>
                <option value="27">GPIO 27</option>
                <option value="32">GPIO 32</option>
                <option value="33">GPIO 33</option>
                <option value="34">GPIO 34 (ONLY INPUT)</option>
                <option value="35">GPIO 35 (ONLY INPUT)</option>
                <option value="36">GPIO 36 (ONLY INPUT)</option>
            </select>
            <div>
                <button type="submit" name="state" value="1" class="btn btn-gpio">Set HIGH</button>
                <button type="submit" name="state" value="0" class="btn btn-off">Set LOW</button>
            </div>
        </form>
    </div>
    
    <div>
        <a href="/restart"><button class="btn" style="background-color: #555555;">RESTART</button></a>
    </div>
   
</body>
</html>"""

def get_html_alert(message):
    
    response = """HTTP/1.1 200 OK
Content-Type: text/html

<html>
<body>
<script>
alert("Successful! {message}");
window.location.href = "/";  // 提示后返回首页
</script>
</body>
</html>"""
    return response
    
    
    
    
    